package com.burgeon.backend.SHOP.controller;

import com.burgeon.backend.SHOP.entity.Advertising;
import com.burgeon.backend.SHOP.entity.Banner;
import com.burgeon.backend.SHOP.entity.IndexImg;
import com.burgeon.backend.SHOP.entity.Seckill;
import com.burgeon.backend.SHOP.service.IndexService;
import com.burgeon.backend.mappers.AccountMapper;
import com.burgeon.backend.service.ComplementService;
import com.burgeon.backend.stsutil.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("shop/index")
public class IndexController extends BaseController {

    @Autowired
    private AccountMapper accountMapper;
    @Autowired
    private ComplementService complementService;
    @Autowired
    private IndexService indexService;

    @RequestMapping("advertising")
    public ResponseResult<List<Advertising>> GetAdvertising(HttpSession session){
        String token = session.getAttribute("token").toString();
        List<Advertising> data = indexService.GetAdvertising(token);
        return new ResponseResult<List<Advertising>>(SUCCESS,data);
    }

    @RequestMapping("indeximg")
    public ResponseResult<IndexImg> GetIndexImg(HttpSession session){
        String token = session.getAttribute("token").toString();
        IndexImg data = indexService.getIndexImg(token);
        return new ResponseResult<IndexImg>(SUCCESS,data);
    }

    @RequestMapping("seckill")
    public ResponseResult<Seckill> GetSeckill(HttpSession session){
        String token = session.getAttribute("token").toString();
        Seckill data = indexService.getSeckill(token);
        return new ResponseResult<Seckill>(SUCCESS,data);
    }

    @RequestMapping("banner")
    public ResponseResult<List> GetBanner(HttpSession session){
        String token = session.getAttribute("token").toString();

        ArrayList<Banner> data = indexService.GetIndexBanner(token);
        return new ResponseResult<List>(SUCCESS,data);
    }

    /**
     * 会员任务
     * @param token
     * @param phone
     * @param uid
     * @param session
     * @return
     */
    @RequestMapping("vipshow")
    public ResponseResult<List> VipShowData(String token, String phone,String uid, HttpSession session) {
        session.setAttribute("token",token);
        session.setAttribute("uid",uid);
        session.setAttribute("phone",phone);
        String account = accountMapper.GetAccountForToken(token);
        ArrayList data = complementService.getComplementSwitch(phone, account);
        return new ResponseResult<List>(SUCCESS, data);
    }
}
